﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using Billing.Controls;
using Billing.Utilities;
using System.Configuration;

namespace Billing
{
    public partial class NewPrinter : Form
    {
        PaperSize psize;
        DataSet dsDetails;

        public NewPrinter()
        {
            InitializeComponent();
        }

        public NewPrinter(DataSet ds)
        {
            InitializeComponent();
            dsDetails = ds;
        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            double totalQty = 0;
            double total14Point5VatAmt = 0d;
            double total5VatAmt = 0d;

            e.PageSettings.PaperSize = psize;
            e.Graphics.DrawString("KS BAKERS", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 100, -3);
            //e.Graphics.DrawString("BHAGYA NAGAR COLONY. PH 66200023", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 15, 15);
            e.Graphics.DrawString(ConfigurationManager.AppSettings["ColonyName"], new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 15, 15);
            e.Graphics.DrawString(ConfigurationManager.AppSettings["TinNo"], new Font(new FontFamily("Times New Roman"), 11, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 80, 30);

            if (dsDetails != null)
            {
                e.Graphics.DrawString("Cashier Name: " + dsDetails.Tables[0].Rows[0]["UserName"].ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, 50);
                e.Graphics.DrawString("Date:" + dsDetails.Tables[0].Rows[0]["BillDate"].ToString() + " " + dsDetails.Tables[0].Rows[0]["BillTime"].ToString() + "    Bill No:" + dsDetails.Tables[0].Rows[0]["BillNo"].ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 9, 65);

                int lineCounter = 80;
                e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                lineCounter += 15;
                e.Graphics.DrawString("Item Name                    Rate        Qty       Amount", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                lineCounter += 15;
                e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);

                lineCounter += 15;
                double totalAmt = 0d;
                //double tax14Point5 = 0d;
                //double tax5 = 0d;

                foreach (DataRow row in dsDetails.Tables[1].Rows)
                {
                    double totalPrice = double.Parse(row["Price"].ToString());
                    double qty = double.Parse(row["Qty"].ToString());
                    totalQty += qty;
                    totalAmt += totalPrice;

                    e.Graphics.DrawString(row["ItemName"].ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                    e.Graphics.DrawString(row["Price"].ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter);

                    if (row["AcceptDecimalStock"].ToString() == "True")
                    {
                        e.Graphics.DrawString(row["Qty"].ToString() + (row["Qty"].ToString() == "1" ? " kg" : " kgs"), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 205, lineCounter);
                    }
                    else
                    {
                        e.Graphics.DrawString(row["Qty"].ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 205, lineCounter);
                    }

                    e.Graphics.DrawString(row["Amount"].ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 260, lineCounter);
                    lineCounter += 15;
                }

                e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                lineCounter += 15;
                e.Graphics.DrawString("Items: " + dsDetails.Tables[1].Rows.Count + "                           Total Qty: " + totalQty.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                lineCounter += 20;

                double totalPayable = 0d;

                if (dsDetails.Tables[0].Rows[0]["DiscountByPercentage"].ToString() != "0")
                {
                    e.Graphics.DrawString("Disc @ " + dsDetails.Tables[0].Rows[0]["DiscountByPercentage"].ToString() + " %=-" + Math.Round(double.Parse(dsDetails.Tables[0].Rows[0]["DiscountByPercentage"].ToString()) / 100 * totalAmt, 2) + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter - 5);
                    e.Graphics.DrawString("Total Amount: " + totalAmt + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter - 5);

                    totalPayable = Math.Round(totalAmt - (double.Parse(dsDetails.Tables[0].Rows[0]["DiscountByPercentage"].ToString()) / 100) * PrintCommon.TotalAmt, 2);
                    e.Graphics.DrawString("Total Payable: " + totalPayable + "/-", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter + 10);
                }
                else if (dsDetails.Tables[0].Rows[0]["DiscountByCost"].ToString() != "0")
                {
                    e.Graphics.DrawString("Disc in Rs = -" + dsDetails.Tables[0].Rows[0]["DiscountByCost"].ToString() + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter - 5);
                    e.Graphics.DrawString("Total Amount: " + totalAmt + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter - 5);

                    totalPayable = (totalAmt - double.Parse(dsDetails.Tables[0].Rows[0]["DiscountByCost"].ToString()));
                    e.Graphics.DrawString("Total Payable: " + totalPayable + "/-", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter + 10);
                }
                else
                {
                    totalPayable = double.Parse(dsDetails.Tables[0].Rows[0]["TotalNetAmount"].ToString());
                    e.Graphics.DrawString("Total Payable: " + totalPayable + "/-", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                }

                lineCounter += 15;
                e.Graphics.DrawString("Cash : " + totalPayable + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);

                e.Graphics.DrawString("Thank You", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 115, lineCounter + 40);
                e.Graphics.DrawString("Your Bill Includes 14.5% Tax = " + (totalPayable * (14.5 / 100)) + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 40, lineCounter + 70);

                e.Graphics.RotateTransform(45);
                e.Graphics.DrawString("DUPLICATE", new Font(new FontFamily("Times New Roman"), 45, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Gray, 40, 0);
            }
            else
            {
                if (Storage.CreditNoteCompany == null || Storage.CreditNoteCompany == string.Empty)
                {
                    e.Graphics.DrawString("Cashier Name: " + Storage.LoginUser, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, 50);
                }
                else
                {
                    e.Graphics.DrawString("Cashier Name: " + Storage.LoginUser, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, 50);
                }

                //e.Graphics.DrawString("Date:" + DateTime.Now.ToString("dd/MM/yy") + "  " + DateTime.Now.ToShortTimeString() + "    Bill No:" + Storage.BillNo, new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 9, 65);
                if (Storage.BillDate == null || Storage.BillDate == string.Empty)
                {
                    e.Graphics.DrawString("Date:" + DateTime.Now.ToString("dd/MM/yy") + "  " + DateTime.Now.ToShortTimeString() + "    Bill No:" + Storage.BillNo, new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 9, 65);
                }
                else
                {
                    e.Graphics.DrawString("Date:" + Storage.BillDate + "    Bill No:" + Storage.BillNo, new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 9, 65);
                }

                int lineCounter = 80;

                if (Storage.CreditNoteCompany != null && Storage.CreditNoteCompany != string.Empty)
                {
                    e.Graphics.DrawString("Bill For: " + Storage.CreditNoteCompany, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Black, 10, lineCounter);
                    lineCounter += 15;
                }

                e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                lineCounter += 15;
                e.Graphics.DrawString("Item Name                    Rate        Qty       Amount", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                lineCounter += 15;
                e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);

                lineCounter += 15;
                double totalAmt = 0d;

                if (PrintCommon.PrintItems != null && PrintCommon.PrintItems.Count > 0)
                {
                    foreach (BillingGridItemControl item in PrintCommon.PrintItems)
                    {
                        if (item.txtCode.Text != string.Empty)
                        {
                            double totalPrice = double.Parse(item.txtPrice.Text);
                            double qty = double.Parse(item.txtQty.Text);
                            totalQty += qty;
                            totalAmt += totalPrice;

                            if (item.vat != null && item.vat.Text != "0" && item.vat.Text != string.Empty)
                            {
                                if (item.vat.Text == "14.5")
                                {
                                    total14Point5VatAmt += totalPrice * 0.145;
                                }
                                else
                                {
                                    total5VatAmt += totalPrice * 0.05;
                                }
                            }

                            e.Graphics.DrawString(item.txtDesc.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                            e.Graphics.DrawString((totalPrice / qty).ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter);

                            if (item.acceptDecimalStock.Text == "True")
                            {
                                e.Graphics.DrawString(item.txtQty.Text + (item.txtQty.Text == "1" ? " kg" : " kgs"), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 205, lineCounter);
                            }
                            else
                            {
                                e.Graphics.DrawString(item.txtQty.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 205, lineCounter);
                            }

                            e.Graphics.DrawString(item.txtPrice.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 260, lineCounter);

                            lineCounter += 15;
                        }
                    }
                    e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                    lineCounter += 15;
                    e.Graphics.DrawString("Items: " + PrintCommon.PrintItems.Count + "                           Total Qty: " + totalQty.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                    lineCounter += 20;
                }
                else if (PrintCommon.CreditNoteItems != null && PrintCommon.CreditNoteItems.Count > 0)
                {
                    foreach (CreditNoteBillingGridItemControl item in PrintCommon.CreditNoteItems)
                    {
                        if (item.txtCode.Text != string.Empty)
                        {
                            double totalPrice = double.Parse(item.txtPrice.Text);
                            double qty = double.Parse(item.txtQty.Text);
                            totalQty += qty;
                            totalAmt += totalPrice;

                            e.Graphics.DrawString(item.txtDesc.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                            e.Graphics.DrawString((totalPrice / qty).ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter);
                            e.Graphics.DrawString(item.txtQty.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 205, lineCounter);
                            e.Graphics.DrawString(item.txtPrice.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 260, lineCounter);

                            lineCounter += 15;
                        }
                    }
                    e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                    lineCounter += 15;
                    e.Graphics.DrawString("Items: " + PrintCommon.CreditNoteItems.Count + "                           Total Qty: " + totalQty.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                    lineCounter += 20;
                }
                else if (PrintCommon.BulkOrderItems != null && PrintCommon.BulkOrderItems.Count > 0)
                {
                    foreach (BulkOrderBillingGridItemControl item in PrintCommon.BulkOrderItems)
                    {
                        if (item.txtCode.Text != string.Empty)
                        {
                            double totalPrice = double.Parse(item.txtPrice.Text);
                            double qty = double.Parse(item.txtQty.Text);
                            totalQty += qty;
                            totalAmt += totalPrice;

                            e.Graphics.DrawString(item.txtDesc.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                            e.Graphics.DrawString((totalPrice / qty).ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter);
                            e.Graphics.DrawString(item.txtQty.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 205, lineCounter);
                            e.Graphics.DrawString(item.txtPrice.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 260, lineCounter);

                            lineCounter += 15;
                        }
                    }
                    e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                    lineCounter += 15;
                    e.Graphics.DrawString("Items: " + PrintCommon.BulkOrderItems.Count + "                           Total Qty: " + totalQty.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                    lineCounter += 20;
                }
                else if (PrintCommon.VendorItems != null && PrintCommon.VendorItems.Count > 0)
                {
                    foreach (VendorBillingGridItemControl item in PrintCommon.VendorItems)
                    {
                        if (item.txtCode.Text != string.Empty)
                        {
                            double totalPrice = double.Parse(item.txtPrice.Text);
                            double qty = double.Parse(item.txtQty.Text);
                            totalQty += qty;
                            totalAmt += totalPrice;

                            e.Graphics.DrawString(item.txtDesc.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                            e.Graphics.DrawString((totalPrice / qty).ToString(), new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter);
                            e.Graphics.DrawString(item.txtQty.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 205, lineCounter);
                            e.Graphics.DrawString(item.txtPrice.Text, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 260, lineCounter);

                            lineCounter += 15;
                        }
                    }
                    e.Graphics.DrawString("--------------------------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter);
                    lineCounter += 15;
                    e.Graphics.DrawString("Items: " + PrintCommon.VendorItems.Count + "                           Total Qty: " + totalQty.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                    lineCounter += 20;
                }

                double totalPayable = 0d;

                if (Storage.DiscountByPercentage != null && Storage.DiscountByPercentage != string.Empty)
                {
                    e.Graphics.DrawString("Disc @ " + Storage.DiscountByPercentage + " %=-" + Math.Round(double.Parse(Storage.DiscountedAmt) / 100 * PrintCommon.TotalAmt, 2) + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 10, lineCounter - 5);
                    e.Graphics.DrawString("Total Amount: " + PrintCommon.TotalAmt + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter - 5);

                    totalPayable = Math.Round(PrintCommon.TotalAmt - (double.Parse(Storage.DiscountByPercentage) / 100) * PrintCommon.TotalAmt, 2);
                    e.Graphics.DrawString("Total Payable: " + totalPayable + "/-", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter + 10);
                }
                else if (PrintCommon.Discount != 0)
                {
                    e.Graphics.DrawString("Disc in Rs = -" + Storage.DiscountedAmt + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter - 5);
                    e.Graphics.DrawString("Total Amount: " + PrintCommon.TotalAmt + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 155, lineCounter - 5);

                    totalPayable = (PrintCommon.TotalAmt - PrintCommon.Discount);
                    e.Graphics.DrawString("Total Payable: " + totalPayable + "/-", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter + 10);
                }
                else
                {
                    totalPayable = PrintCommon.TotalAmt;
                    e.Graphics.DrawString("Total Payable: " + totalPayable + "/-", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                }

                if (Storage.CashAmt != 0d)
                {
                    lineCounter += 15;
                    e.Graphics.DrawString("Cash : " + (PrintCommon.TotalAmt - PrintCommon.Discount) + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                }
                if (Storage.CardAmt != 0d)
                {
                    lineCounter += 15;
                    e.Graphics.DrawString("Card : " + Storage.CardAmt.ToString() + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                }
                if (Storage.SodexhoAmt != 0d)
                {
                    lineCounter += 15;
                    e.Graphics.DrawString("Sodexho : " + Storage.SodexhoAmt.ToString() + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 20, lineCounter);
                }

                lineCounter += 20;

                if (PrintCommon.IsTokenRequired)
                    e.Graphics.DrawString("Token: " + PrintCommon.Token, new Font(new FontFamily("Times New Roman"), 18, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Black, 100, lineCounter);

                e.Graphics.DrawString("Thank You", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 115, lineCounter + 40);
                //e.Graphics.DrawString("Your Bill Includes 14.5% Tax = " + (totalPayable * (14.5 / 100)) + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 40, lineCounter + 70);
                e.Graphics.DrawString("Your Bill Includes", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 40, lineCounter + 70);
                if (total14Point5VatAmt != 0)
                {
                    e.Graphics.DrawString("14.5% Tax = " + total14Point5VatAmt + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 100, lineCounter + 85);
                }

                if (total5VatAmt != 0)
                {
                    e.Graphics.DrawString("      5% Tax = " + total5VatAmt + "/-", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 100, lineCounter + 100);
                }

                if (PrintCommon.BulkOrderItems != null && PrintCommon.BulkOrderItems.Count > 0)
                    e.Graphics.DrawString("    BULK", new Font(new FontFamily("Times New Roman"), 35, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Gray, 10, 0);
            }
        }

        private void printDocument1_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
        {
            if (dsDetails != null)
            {
                psize = new PaperSize("saurabh", 300, 305 + dsDetails.Tables[1].Rows.Count * 15);
                e.PageSettings.PaperSize = psize;
            }
            else
            {
                if (PrintCommon.PrintItems != null && PrintCommon.PrintItems.Count != 0)
                {
                    psize = new PaperSize("saurabh", 300, 315 + PrintCommon.PrintItems.Count * 15);
                    e.PageSettings.PaperSize = psize;
                }
                else if (PrintCommon.CreditNoteItems != null && PrintCommon.CreditNoteItems.Count != 0)
                {
                    psize = new PaperSize("saurabh", 300, 320 + PrintCommon.CreditNoteItems.Count * 15);
                    e.PageSettings.PaperSize = psize;
                }
                else if (PrintCommon.BulkOrderItems != null && PrintCommon.BulkOrderItems.Count != 0)
                {
                    psize = new PaperSize("saurabh", 300, 305 + PrintCommon.BulkOrderItems.Count * 15);
                    e.PageSettings.PaperSize = psize;
                }
                else if (PrintCommon.VendorItems != null && PrintCommon.VendorItems.Count != 0)
                {
                    psize = new PaperSize("saurabh", 300, 320 + PrintCommon.VendorItems.Count * 15);
                    e.PageSettings.PaperSize = psize;
                }
            }
        }
    }
}